package com.liuyang.second.concurrency.chapter3;

import java.util.ArrayList;
import java.util.List;

public class Subject {

    private List<ObServer> obServers = new ArrayList<>();

    private int state;

    public void setObServers(List<ObServer> obServers) {
        this.obServers = obServers;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        if(this.state !=state) {
            this.state = state;
            notifyAllObServer();
        }
    }

    public void notifyAllObServer(){
        obServers.stream().forEach(ObServer::update);
    }

    public void attach(ObServer obServer){
        obServers.add(obServer);
    }
}
